package com.lixin.controller;

import com.lixin.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("upload")
public class UploadController {
    @PostMapping
    public Result index(MultipartFile file) throws IOException {
        String dir = "D:\\JavaProjects\\spring-boot-demo\\src\\main\\resources\\static\\";
        String relativeDir = "/static/";
        String originalFilename = file.getOriginalFilename();
        file.transferTo(new File(dir + originalFilename));
        return Result.success(relativeDir + originalFilename);
    }
}
